package com.yonyou.jrmob.contacts.schedule.activity;

/**
 * Created by 11985 on 2016/11/1.
 */

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.yonyou.jrmob.contacts.R;
import com.yonyou.jrmob.contacts.schedule.vo.RemindBean;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import jrmob.yonyou.com.commonlib.app_config_tool.tool.base.StatusBarUtil;
import jrmob.yonyou.com.commonlib.baseui.base.BaseActivityMob_lib;

/**
 * 描述:提醒
 *
 * @下午8:08:51
 * @author zhangg
 */
public class ScheduleRemindActivity extends BaseActivityMob_lib {

    private Button button_left;
    private ListView lv_aa;
    private List<RemindBean> list;
    private String pk;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initActionbar();
        setContentView(R.layout.scheduleremindactivity);
        initView();
        initListener();
        initData();
    }

    public void initView() {
        button_left = (Button) findViewById(R.id.button_left);
        lv_aa = (ListView) findViewById(R.id.lv_aa);

    }

    @Override
    protected void onResume() {
        super.onResume();
        if (null != getIntent().getExtras()) {
            pk = getIntent().getExtras().getString("pk", "");
        } else {
            pk = "";
        }
        StatusBarUtil.setStatusBarColor(this, R.color.schedule_status_bar_bg);

    }

    public void initListener() {
        button_left.setOnClickListener(this);
        lv_aa.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                // ScheduleRemindActivity.this.showMessage(ScheduleRemindActivity.this,
                // list.get(arg2)
                // .getName() + " " + list.get(arg2).getTime());

                Intent intent = new Intent(ScheduleRemindActivity.this, ScheduleMainActivity.class);
                /*Bundle bundle = new Bundle();
                bundle.putString("name", list.get(arg2).getName());
                bundle.putString("time", list.get(arg2).getTime());
                bundle.putString("pk", pk);
                intent.putExtras(bundle);*/
                writeLocationFile("tv_tixingname", list.get(arg2).getName());
                writeLocationFile("tv_tixingtime", list.get(arg2).getTime());
                setResult(222, intent);
                finish();
            }
        });
    }

    public void initData() {
        List<String> nameList = new ArrayList<String>();
        nameList.add("无");
        nameList.add("日程发生时");
        nameList.add("5分钟前");
        nameList.add("15分钟前");
        nameList.add("30分钟前");
        nameList.add("1小时前");
        nameList.add("2小时前");
        nameList.add("1天前");
        nameList.add("2天前");
        nameList.add("1周前");
        nameList.add("2周前");
        nameList.add("1月前");
        nameList.add("2月前");
        list = new ArrayList<RemindBean>();
        for (int i = 1; i < 13; i++) {
            RemindBean vo = new RemindBean();
            vo.setName(nameList.get(i));
            vo.setTime(getCurrentDate());
            list.add(vo);
        }
        myAdapter adapter = new myAdapter(this, list);
        lv_aa.setAdapter(adapter);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if(v.getId() == R.id.button_left){
            finish();
        }
    }


    /***
     * 描述:adapter
     *
     * @上午9:11:44
     * @author zhangg
     */
    class myAdapter extends BaseAdapter {

        private List<RemindBean> list;
        private Context context;

        public myAdapter(Context context, List<RemindBean> list) {
            this.list = list;
            this.context = context;
        }

        @Override
        public int getCount() {
            if (null == list) {
                return 0;
            }
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            viewholder holder = null;
            if (convertView == null) {
                holder = new viewholder();
                convertView = View.inflate(context, R.layout.scheduleremind_item, null);
                holder.remain_name = (TextView) convertView.findViewById(R.id.remain_name);
                holder.remain_time = (TextView) convertView.findViewById(R.id.remain_time);
                holder.remind_line = (TextView) convertView.findViewById(R.id.remind_line);
                convertView.setTag(holder);
            } else {
                holder = (viewholder) convertView.getTag();
            }
            if (position % 2 == 0) {
                holder.remind_line.setVisibility(View.INVISIBLE);
            } else {
                holder.remind_line.setVisibility(View.VISIBLE);
            }
            RemindBean vo = list.get(position);
            holder.remain_name.setText(vo.getName());
            holder.remain_time.setText(vo.getTime());

            return convertView;
        }

    }
    public String getCurrentDate() {
        // SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dateFormater = new SimpleDateFormat(
                "yyyy-MM-dd HHmmss");
        Date date = new Date();
        // System.out.print();?
        return dateFormater.format(date);
    }

    class viewholder {
        TextView remain_name;
        TextView remain_time;
        TextView remind_line;
    }
}

